<template>
	<view>
		<view class="my_head" v-if="member.m_id">
			<image :src="member.m_face?member.m_face:'/static/img/face.png'"
				@click="funHref('/pages/my/detail/detail')">
			</image>
			<view class="con">
				<text @click="funHref('/pages/my/detail/detail')">
					{{member.m_name}}
					<i v-if="member.MemberGrade">{{member.MemberGrade?member.MemberGrade.mg_title:''}}</i>
				</text>
				<view>
					<em @click="funHref('/pages/my/integral/integral')">
						<i class="iconfont icon-jifen"></i>
						{{member.m_integral}} {{$t('integral')}}
					</em>
					<em @click="funHref('/pages/my/detail/detail')"><i class="iconfont icon-ziliao"></i>{{$t('personal_data')}}</em>
				</view>
			</view>
			<view class="set" @click="funSet('/pages/my/set/set')"><i class="iconfont icon-shezhi"></i></view>
		</view>
		<view class="my_head" v-else>
			<image src="/static/img/face.png" @click="funHref('/pages/my/detail/detail')">
			</image>
			<view class="con" @click="funHref('/pages/my/detail/detail')">
				<text style="display: block;margin-top: 30rpx;font-size: 40rpx;">
					{{$t('go_login')}}
				</text>
			</view>
			<view class="set" @click="funSet('/pages/my/set/set')"><i class="iconfont icon-shezhi"></i></view>
		</view>
		<view class="my_imp">
			<view @click="funHref('/pages/my/recharge/recharge')">
				<text>{{member.m_balance?member.m_balance:0}}</text>
				<label>{{$t('balance')}}</label>
			</view>
			<view @click="funHref('/pages/my/collection/collection')">
				<text>{{list_statistics[0].count}}</text>
				<label>{{$t('collect')}}</label>
			</view>
			<view @click="funHref('/pages/my/coupon/coupon')">
				<text>{{list_statistics[1].count}}</text>
				<label>{{$t('coupons')}}</label>
			</view>
		</view>
		<view class="my_tool">
			<h3>
				{{$t('my_order')}}<a @click="funHref('/pages/my/orders/orders?state=0')">{{$t('all_order')}}<i
						class="iconfont icon-xiangyou"></i></a>
			</h3>
			<div>
				<a @click="funHref('/pages/my/orders/orders?state=1')">
					<i class="iconfont icon-daifukuan"></i>
					<font>{{$t('pay_state1')}}</font>
				</a>
				<a @click="funHref('/pages/my/orders/orders?state=2')">
					<i class="iconfont icon-daifahuo2"></i>
					<font>{{$t('pay_state2')}}</font>
				</a>
				<a @click="funHref('/pages/my/orders/orders?state=3')">
					<i class="iconfont icon-daishouhuo2"></i>
					<font>{{$t('pay_state3')}}</font>
				</a>
				<a @click="funHref('/pages/my/orders/orders?state=4')">
					<i class="iconfont icon-daipingjia2"></i>
					<font>{{$t('pay_state4')}}</font>
				</a>
				<a @click="funHref('/pages/my/orders/orders?state=50')">
					<i class="iconfont icon-shouhouwuyou"></i>
					<font>{{$t('pay_state5')}}</font>
				</a>
			</div>
		</view>
		<swiper class="banner_con" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
			:duration="duration">
			<block v-for="(item,index) in list_adv" :key="index">
				<swiper-item>
					<image mode="widthFix" :src="item.adv_img"></image>
				</swiper-item>
			</block>
		</swiper>
		<view class="my_fun">
			<view @click="funHref('/pages/my/receive_coupon/receive_coupon')">
				<label class="iconfont icon-wodejuanbao"></label>
				<text>{{$t('coupons')}}</text>
			</view>
			<view @click="funHref('/pages/my/integral/integral')">
				<label class="iconfont icon-jifen"></label>
				<text>{{$t('integral')}}</text>
			</view>
			<view @click="funHref('/pages/my/history/history')">
				<label class="iconfont icon-liulanlishi"></label>
				<text>{{$t('browsing_history')}}</text>
			</view>
			<view @click="funHref('/pages/help/help')">
				<label class="iconfont icon-bangzhuzhongxin3"></label>
				<text>{{$t('help')}}</text>
			</view>
			<view @click="funHref('/pages/my/feedback/feedback')">
				<label class="iconfont icon-yjfk"></label>
				<text>{{$t('feedback')}}</text>
			</view>
			<view @click="funHref('/pages/message/message')">
				<label class="iconfont icon-xiaoxi"></label>
				<text>{{$t('message')}}</text>
			</view>
		</view>
		<view class="btn_obtain btn_center" v-if="member.m_id" @click="funQuit">
			{{$t('exit')}}
		</view>
		<!--刷新-->
		<view class='loadind_con' v-if="isLoading">
			<view class="loading">
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
			</view>
		</view>
		<!--客服按钮-->
		<view class="kefu_btn" @click="funHref('/pages/chatroom/chatroom')">
			<text class="gui-footer-icon-buttons-icon gui-block-text gui-icons">&#xe626;</text>
			<text class="gui-footer-icon-buttons-text gui-block-text gui-icons">{{$t('give_service')}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading: false,
				member: {}, //会员
				list_statistics: [{
					count: 0
				}, {
					count: 0
				}],
				indicatorDots: true,
				autoplay: true,
				interval: 3000,
				duration: 500,
				list_adv: [], //滚动广告
			}
		},
		onReady() {
			uni.setTabBarItem({
				index: 0,
				text: this.$t('home')
			});
			uni.setTabBarItem({
				index: 1,
				text: this.$t('type')
			});
			uni.setTabBarItem({
				index: 2,
				text: this.$t('cart')
			});
			uni.setTabBarItem({
				index: 3,
				text: this.$t('member')
			});
			
			uni.setNavigationBarTitle({
				title: this.$t('member')
			})
		},
		onLoad() {
			var _this = this;

			//获取登录信息
			_this.getUserInfo();

			//定义通讯方法 - 获取登录信息
			uni.$on('load_getUserInfo', function(data) {
				_this.getUserInfo();
			});

			//模拟广告图
			_this.list_adv.push({
				adv_img: '/static/img/banner1.png'
			});
			_this.list_adv.push({
				adv_img: '/static/img/banner2.jpg'
			});
			_this.list_adv.push({
				adv_img: '/static/img/banner.jpg'
			});
		},
		methods: {
			//获取登录信息
			getUserInfo() {
				var _this = this;

				var token = uni.getStorageSync("token");
				var member = uni.getStorageSync("member");

				if (token && member) {
					_this.member = member;

					//获取统计
					_this.fun_request("/Api/Member/GetStatistics", {}, function(res) {
						_this.list_statistics = res.data;
					});

					_this.isLoading = false;
				}
			},
			//跳转
			funHref: function(url) {
				if (this.member.m_id == undefined) {
					this.fun_navigateTo('/pages/login/index');
					return;
				}

				this.fun_navigateTo(url);
			},
			//跳转设置页
			funSet: function(url) {
				this.fun_navigateTo(url);
			},
			//退出
			funQuit() {
				this.member = {};
				uni.clearStorageSync('token');
				uni.clearStorageSync('member');

				//更新购物车
				uni.$emit('load_getCart');

				this.list_statistics = [{
					count: 0
				}, {
					count: 0
				}];
			},
		}
	}
</script>


<style lang="scss">
	page {
		background-color: #F7F7F7;
		padding-bottom: 30rpx;
	}

	.my_head {
		width: 100%;
		padding: 40rpx 4%;
		overflow: hidden;
		position: relative;

		.set {
			position: absolute;
			right: 3%;
			top: 30rpx;

			i {
				font-size: 50rpx;
				color: #F85F69;
			}
		}

		image {
			float: left;
			width: 140rpx;
			height: 140rpx;
			border-radius: 50%;
		}

		view.con {
			display: block;
			padding: 10rpx 0 0 170rpx;

			text {
				font-size: 50rpx;
				font-weight: bold;

				i {
					font-style: normal;
					margin-left: 15rpx;
					background: linear-gradient(to right, #92C7FF, #79BBFE);
					color: #fff;
					font-size: 22rpx;
					font-weight: normal;
					border-radius: 10rpx;
					padding: 5rpx 10rpx;
				}
			}

			view {
				display: block;
				margin-top: 10rpx;

				em {
					float: left;
					background-color: #F85F69;
					color: #fff;
					font-size: 22rpx;
					border-radius: 10rpx;
					padding: 5rpx 10rpx;
					margin-right: 10rpx;
					font-style: normal;

					i {
						font-size: 22rpx;
						vertical-align: middle;
						display: inline-block;
						margin: -5rpx 5rpx 0 0;
					}
				}
			}
		}
	}

	.my_imp {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		margin: 10rpx auto 0;
		width: 94%;
		padding: 30rpx 0;
		background-color: #fff;
		border-radius: 15rpx;

		view {
			-webkit-box-flex: 1;
			-webkit-flex: 1;
			flex: 1;
			text-align: center;
			border-right: 1px solid #eee;

			text {
				display: block;
				color: #F85F69;
				font-size: 32rpx;
				margin-bottom: 10rpx;
				font-weight: bold;
			}

			label {
				display: block;
				font-size: 26rpx;
				color: #666;
			}
		}

		view:last-child {
			border: 0;
		}
	}

	.my_tool {
		width: 94%;
		margin: 30rpx auto 0;
		display: block;
		background-color: #fff;
		border-radius: 15rpx;

		h3 {
			display: block;
			border-bottom: 1px solid #F0F0F0;
			height: 90rpx;
			line-height: 90rpx;
			padding: 0 3%;
			font-size: 34rpx;
			color: #333;
			font-weight: bold;

			a {
				float: right;
				font-size: 28rpx;
				color: #717171;
				font-weight: normal;

				i {
					display: inline-block;
					vertical-align: middle;
					font-size: 28rpx;
					margin: -5rpx 0 0 0;
				}
			}
		}

		div {
			display: block;
			overflow: hidden;
			width: 100%;

			a {
				float: left;
				width: 20%;
				text-align: center;
				padding: 30rpx 0;

				i {
					display: block;
					color: #FF5E53;
					font-size: 60rpx;
					margin-bottom: 10rpx;
				}

				font {
					display: block;
					font-size: 26rpx;
					color: #666;
				}
			}
		}
	}

	.my_fun {
		width: 94%;
		margin: 30rpx auto 0;
		display: block;
		background-color: #fff;
		border-radius: 15rpx;
		overflow: hidden;
		padding: 20rpx 0;

		view {
			float: left;
			width: 25%;
			text-align: center;
			padding: 20rpx 0;

			label {
				display: block;
				font-size: 60rpx;
				margin-bottom: 10rpx;
			}

			text {
				display: block;
				font-size: 26rpx;
				color: #666;
			}
		}

		view:nth-child(1) label {
			background: linear-gradient(to right, #FFACAC, #FF8B8B);
			-webkit-background-clip: text;
			color: transparent;
		}

		view:nth-child(2) label {
			background: linear-gradient(to right, #92C7FF, #79BBFE);
			-webkit-background-clip: text;
			color: transparent;
		}

		view:nth-child(3) label {
			background: linear-gradient(to right, #75E2F2, #5ED2E3);
			-webkit-background-clip: text;
			color: transparent;
		}

		view:nth-child(4) label {
			background: linear-gradient(to right, #D8A6FF, #CF93FF);
			-webkit-background-clip: text;
			color: transparent;
		}

		view:nth-child(5) label {
			background: linear-gradient(to right, #B7BAFF, #A6AAFF);
			-webkit-background-clip: text;
			color: transparent;
		}

		view:nth-child(6) label {
			background: linear-gradient(to right, #E6C8FF, #D197FF);
			-webkit-background-clip: text;
			color: transparent;
		}
	}
</style>